package com.qyl.honghengshop.dao.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.qyl.honghengshop.dao.BaseDao;
import com.qyl.honghengshop.dao.TimeDao;
import com.qyl.honghengshop.dto.TimeLimit;
import com.qyl.honghengshop.mapper.TimeMapper;
import com.qyl.honghengshop.utils.PageBean;

public class TimeDaoImpl extends BaseDao implements TimeDao {

	@Override
	public int getRecordCount(TimeLimit time) {

		SqlSession sqlSession = this.getSqlSession();
		
		TimeMapper timeMapper = sqlSession.getMapper(TimeMapper.class);
		
		int recordCount = timeMapper.getRecordCount(time);
		
		this.closeSqlSession();
		
		return recordCount;

	}

	@Override
	public void timeList(PageBean pageBean, TimeLimit time) {
		
		SqlSession sqlSession = this.getSqlSession();
		
		TimeMapper timeMapper = sqlSession.getMapper(TimeMapper.class);
		
		List<TimeLimit> list = timeMapper.timeList(pageBean,time);
		
		pageBean.setList(list);
		
		this.closeSqlSession();

	}

	@Override
	public int timeAdd(TimeLimit time) {
		
		SqlSession sqlSession = this.getSqlSession();
		
		TimeMapper timeMapper = sqlSession.getMapper(TimeMapper.class);
		
		int count = timeMapper.timeAdd(time);
		
		sqlSession.commit();
		
		this.closeSqlSession();
		
		return count;
	}

	@Override
	public int delTime(Integer id) {

		SqlSession sqlSession = this.getSqlSession();
		
		TimeMapper timeMapper = sqlSession.getMapper(TimeMapper.class);
		
		int count = timeMapper.delTime(id);
		
		sqlSession.commit();
		
		this.closeSqlSession();
		
		return count;

	}

	@Override
	public TimeLimit getTimeById(Integer id) {

		SqlSession sqlSession = this.getSqlSession();
		
		TimeMapper timeMapper = sqlSession.getMapper(TimeMapper.class);
		
		TimeLimit time = timeMapper.getTimeById(id);
	
		this.closeSqlSession();
		
		return time;
	}

	@Override
	public int timeUpdate(TimeLimit time) {
		
		SqlSession sqlSession = this.getSqlSession();
		
		TimeMapper timeMapper = sqlSession.getMapper(TimeMapper.class);
		
		int count = timeMapper.timeUpdate(time);
		
		sqlSession.commit();
		
		this.closeSqlSession();
		
		return count;
	}

	@Override
	public List<TimeLimit> getAllTimeLimit() {
	
		SqlSession sqlSession = this.getSqlSession();
		
		TimeMapper timeMapper = sqlSession.getMapper(TimeMapper.class);
		
		List<TimeLimit> list = timeMapper.getAllTimeLimit();

		this.closeSqlSession();
		
		return list;
	}

}
